package com.example.crossborderecommerce.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.crossborderecommerce.entity.CustomerOrder;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.crossborderecommerce.entity.ProductCategory;
import com.example.crossborderecommerce.entity.Shop;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Yolanda
 * @since 2024-05-09
 */
@Mapper
public interface CustomerOrderMapper extends BaseMapper<CustomerOrder> {
    public List<CustomerOrder> getCustomerOrderByPage(Page<CustomerOrder> page,
                                                      @Param("customerName") String customerName,
                                                      @Param("status") String status,
                                                      @Param("logisticsProviderId") String logisticsProviderId,
                                                      @Param("salePromotionId") String salePromotionId);
    public Integer getSaleAmount();
    public Integer getSaleAmountDuration(String startTime, String endTime);
    public Double getSaleMoney();
    public Double getSaleMoneyDuration(String startTime, String endTime);
    public Integer getSaleAmountByNation(String nation);
    public Double getSaleMoneyByNation(String nation);
    public Integer getProductCostByNation(String nation);
    @Select("SELECT pc.name as categoryName, IFNULL(SUM(co.price),0) as saleMoney " +
            "FROM customer_order co " +
            "LEFT JOIN store_commodity sc ON sc.id = co.store_commodity_id " +
            "LEFT JOIN product p ON sc.product_id = p.id " +
            "LEFT JOIN product_category pc ON p.category_id = pc.id " +
            "GROUP BY pc.id, pc.name")
    public List<Map<String, Double>> getSaleMoneyByCategory();
    @Select("SELECT p.name as productName, IFNULL(SUM(co.quantity),0) as saleAmount " +
            "FROM customer_order co " +
            "LEFT JOIN store_commodity sc ON sc.id = co.store_commodity_id " +
            "LEFT JOIN product p ON sc.product_id = p.id " +
            "GROUP BY p.id")
    public List<Map<String, Double>> getSaleAmountByStoreCommodity();
    public Integer getSaleAmountByStoreType(String type);
    public Double getSaleMoneyByStoreType(String type);
    public Double getSaleMoneyByShopId(String shopId);
    public Integer getSaleQuantityByShopId(String shopId);
    @Select("SELECT status, IFNULL(COUNT(*),0) as orderQuantity " +
            "FROM customer_order " +
            "GROUP BY status")
    public List<Map<String, Integer>> getOrderQuantityByStatus();
}
